'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageIntroletterCtrl
 * @description
 * # ManageIntroletterCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
  .controller('ManageIntroletterCtrl', function($scope, $location, $rootScope, openApi, Util, $routeParams, FormSubmit) {
    var id = $scope.process_id = $routeParams.id
    $scope.param = {};
    $scope.choosePeople = function() {
      var relModuleObj = {
        name: "ManageIntroletterCtrl",
        selectTab: "instroductionLetter_select_project",
        selectTabContent: "工程名称"
      };
      // 将列表的数据序列化存入缓存以便回来时候使用
      Util.savaParamForReview($scope.param, id);
      Util.savaDataforsearch(relModuleObj);
      $location.path("finance/choosepeople")
    };
    $scope.submit = function(operationId) {
      // 底部类型end
      var options = {};
      // 流程id
      options.id = id;
      // 根据operationId判断是草稿还是提交
      options.operationId = operationId;
      options.urlParam = openApi.introletter;
      options.param = angular.copy($scope.param, {});
      FormSubmit.submit(options,$scope);
    };
    $scope.validate = function() {
      var reg = /^[1-9]\d*$/;
      if (!$scope.param.projectName) {
        Util.Toast("请选择工程名称");
        return;
      }
      if (!$scope.param.receivingUnit) {
        Util.Toast("请填写接收单位");
        return;
      }
      if (!$scope.param.authorizedEmployee) {
        Util.Toast("请填写授权员工");
        return;
      }
      if (!reg.test($scope.param.authorizedNumber)) {
        Util.Toast("请填写授权人数(为正整数)");
        return;
      }
      if (!reg.test($scope.param.effectiveDays)) {
        Util.Toast("请填写有效天数(为正整数)");
        return;
      }
      if (!$scope.param.effectiveDate) {
        Util.Toast("请选择生效日期");
        return;
      }
      if (!$scope.param.disposeOfThing) {
        Util.Toast("请填写办理事宜");
        return;
      }
      if (!$scope.validation.passvalidation) {
        Util.Toast($scope.validation.tip);
        return;
      }
      return true;
    }

    var init = function() {
      // 获取回显的详细信息
      Util.getDetailData(id, function(data) {
        $scope.param = data;
      });
    };
    // 初始化
    init();

  });